<?
include('adodb/adodb-exceptions.inc.php'); 
require ("comun/ini.php");
if(isset($_POST['JsonEnv'])){
	$JsonRec = new Services_JSON();
	$JsonEnv = new Services_JSON();
	$JsonRec=$JsonRec->decode(str_replace("\\","",$_POST['JsonEnv']));
	try {
		if ($JsonRec->Zona == -1) {
			$q = "SELECT A.* FROM peritos AS A INNER JOIN zonas AS B ON A.id_zona = B.id WHERE B.id=" . $_SESSION['SesionZona'] . " OR B.id IN (SELECT id FROM zonas WHERE id_padre =" . $_SESSION['SesionZona'] .") ORDER BY A.nombre";
		} else {
			$q = "SELECT A.* FROM peritos AS A INNER JOIN zonas AS B ON A.id_zona = B.id WHERE A.id_zona=$JsonRec->Zona OR B.id_padre = $JsonRec->Zona ORDER BY A.nombre";
		}
		$r = $conn->Execute($q);
		$i=0;
		while(!$r->EOF){
			$Perito[$i]['ID'] = (int)$r->fields['codigo'];
			$Perito[$i]['N'] = $r->fields['nombre'];
			$i++;
			$r->movenext();
		}
		if(is_array($Perito)){
			echo $JsonEnv->encode($Perito);
		}else{
			echo false;
		}
	}catch( ADODB_Exception $e ){
		//	echo ERROR_CATCH_GENERICO;
		echo false;
	}
} 
?>
